package com.kasax.basiclib;

import android.util.Log;

public class LifecycleTracer {
    private static final String TAG = AppConstants.LOG_TAG;
    private static final boolean ENABLED = true;

    public static void onMethodStart(String className, String methodName) {
        if (!ENABLED) return;
        Log.d(TAG, String.format("→ %s.%s", getSimpleName(className), methodName));
    }

    public static void recordCost(long cost, String className, String methodName) {
        if (!ENABLED) return;

        if (cost > 16) { // 超过一帧时间警告
            Log.w(TAG, String.format("⚠️ %s.%s cost: %dms",
                    getSimpleName(className), methodName, cost));
        } else {
            Log.d(TAG, String.format("← %s.%s cost: %dms",
                    getSimpleName(className), methodName, cost));
        }
    }

    private static String getSimpleName(String className) {
        if (className == null) return "Unknown";
        int lastDot = className.lastIndexOf('.');
        return lastDot >= 0 ? className.substring(lastDot + 1) : className;
    }
}
